﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using SMS.Domain.Model;

namespace SMS.Domain
{
    class SmsContext : DbContext
    {
        public SmsContext()
            : base("sms")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Keywords>().ToTable("Keywords");
            modelBuilder.Entity<Keywords>().HasKey(p => p.Id);

            modelBuilder.Entity<Cargo>().ToTable("Cargo");
            modelBuilder.Entity<Cargo>().HasKey(p => p.Id);

            modelBuilder.Entity<Customer>().ToTable("Customer");
            modelBuilder.Entity<Customer>().HasKey(p => p.Id);

            modelBuilder.Entity<CustomerPrice>().ToTable("CustomerPrice");
            modelBuilder.Entity<CustomerPrice>().HasKey(p => p.Id);
            modelBuilder.Entity<CustomerPrice>()
                .HasRequired<Cargo>(p=>p.Cargo)
                .WithMany().HasForeignKey(p => p.CargoId);

            modelBuilder.Entity<Invoice>().ToTable("Invoice");
            modelBuilder.Entity<Invoice>().HasKey(p => p.Id);

            modelBuilder.Entity<SaleCargo>().ToTable("SaleCargo");
            modelBuilder.Entity<SaleCargo>().HasKey(p => p.Id);
            modelBuilder.Entity<SaleCargo>()
                .HasRequired<Cargo>(p => p.Cargo)
                .WithMany().HasForeignKey(p => p.CargoId);

            base.OnModelCreating(modelBuilder);
        }
    }
}
